#ifndef boolfuck_h_
#define boolfuck_h_

/* boolfuck.h - by Sam Hughes - boof@samuelhughes.com */

// Copyright 2005 (?) Sam Hughes, feel free to DWTFYWT.

/* A boolpit is an infinite array of bools (growable at both ends) */

/* (Why didn't I just use a pair of vector<uint32_t> to implement
   this?  Maybe because I was dumb.) */

#include <string>
#include <iostream>
#include <vector>

class boolpit {

	unsigned char * beg_;
	unsigned char * mid_;
	unsigned char * end_;

 public:

	boolpit();
	boolpit(const boolpit & copyee);
	~boolpit();

	boolpit & operator=(const boolpit & assignee);

	void set(size_t offset, int i);
	int get(size_t offset);
	void flip(size_t offset);

 private:
	void copy(const boolpit & copyee);
	void grow_and_accommodate(unsigned char * & p);


};

class bf_interpreter {
	struct size_triad {
		size_t lpos, rjump, bjump;
		size_triad(size_t a, size_t b, size_t c)
			: lpos(a), rjump(b), bjump(c) {}
	};

	std::string prog_;
	std::vector<size_triad> brace_pos_;

 public:
	bf_interpreter(std::istream & istr);
	void interpret(std::istream & in, std::ostream & out) const;



};


#endif
